import { action, observable, runInAction } from 'mobx';
import Axios from 'axios';

class TableTest {
  @observable templateList = [];
  @observable page = 1;
  @observable pageSize = 10;
  @observable total = 0;
  @observable loading = false;

  changePagination = (page, pageSize) => {
    this.getTemplateList(page, pageSize)
  }

  @action
  getTemplateList = (page=1, pageSize=10) => {
    this.loading = true;
    Axios.post('/api?getTemplateList', {
      apiName: 'getTemplateList',
      params: {
        page,
        pageSize,
      },
    })
      .then(response => {
        runInAction(() => {
          this.page = page;
          this.pageSize = pageSize;
          this.total = response.data.pagination.total;
          this.templateList = response.data.data;
          this.loading = false;
        })
      })
      .catch(error => {
        console.log(error);
      });
  }

}

export default new TableTest();